unit uAppConfig;

interface

uses
  SysUtils, Classes, uDZPersistent, uDZConfig, uDZFile, uCxtTypes;
  
type
  TAppConfig = class(TDzPersistent)
  private
    fMaxSession: Integer;
    fCoordLocatePoint: Integer;
    fCityLocatePoint: Integer;
    fPackageFormat: TDzArchiveFormat;
    fConnParam: TDzDBConnectionParam;
    fSettings: TServerSetting;
    fPort: Integer;
    fDBConnectionPoolSize: Integer;
    fSmsPoint: Integer;
    fSmsServiceUrl: AnsiString;
    fResolveGISCoord: Boolean;
    fLBSServiceUrl: AnsiString;
    fUseNewTrackServer: Boolean;
    fLBMPTrackServerAddr: AnsiString;
    fLBMPTrackServerPort: Word;
    fDWTrackServerPassword: AnsiString;
    fDWTrackServerUserName: AnsiString;
    fDLVehicleDBHost: AnsiString;
    fUseDLVehicleDB: Boolean;
    fDLVehicleDBPort: Word;
    procedure SetConnParam(const Value: TDzDBConnectionParam);
  public
    constructor Create; override;
    destructor Destroy; override;
  published
    property Port: Integer read fPort write fPort default 7890;
    property MaxSession: Integer read fMaxSession write fMaxSession;
    property DBConnectionPoolSize: Integer
      read fDBConnectionPoolSize write fDBConnectionPoolSize default 20;
    property SmsPoint: Integer read fSmsPoint write fSmsPoint default 10;
    property CoordLocatePoint: Integer
      read fCoordLocatePoint write fCoordLocatePoint default 20;
    property CityLocatePoint: Integer
      read fCityLocatePoint write fCityLocatePoint default 20;
    property PackageFormat: TDzArchiveFormat
      read fPackageFormat write fPackageFormat default afBinary;
    property ConnParam: TDzDBConnectionParam read fConnParam write SetConnParam;
    property SmsServiceUrl: AnsiString read fSmsServiceUrl write fSmsServiceUrl;
    property LBSServiceUrl: AnsiString
      read fLBSServiceUrl write fLBSServiceUrl;

    //decide server or client resolving gis coord(from google)
    property ResolveGISCoord: Boolean
      read fResolveGISCoord write fResolveGISCoord;

    property UseNewTrackServer: Boolean
      read fUseNewTrackServer
      write fUseNewTrackServer default True;
    property LBMPTrackServerAddr: AnsiString
      read fLBMPTrackServerAddr write fLBMPTrackServerAddr;
    property LBMPTrackServerPort: Word
      read fLBMPTrackServerPort write fLBMPTrackServerPort default 5678;
    property DWTrackServerUserName: AnsiString read
      fDWTrackServerUserName write fDWTrackServerUserName;
    property DWTrackServerPassword: AnsiString read
      fDWTrackServerPassword write fDWTrackServerPassword;

    // add by zhouzuoji, 2011-9-27 17:37
    // software database for vehicle client config
    property UseDLVehicleDB: Boolean read fUseDLVehicleDB write fUseDLVehicleDB
      default True;
    property DLVehicleDBHost: AnsiString
      read fDLVehicleDBHost write fDLVehicleDBHost;
    property DLVehicleDBPort: Word read fDLVehicleDBPort write fDLVehicleDBPort
      default 544;

    property Settings: TServerSetting read fSettings write fSettings;
  end;
                               
  function AppConfig: TAppConfig;

implementation

const
  CONFIG_FILE_NAME = 'CxtServer.ini';

var
  AppConfig: TAppConfig;
  ConfigFilePath: string;

function AppConfig: TAppConfig;
begin
  Result := AppConfig;
end;

procedure LoadConfig;
begin
  AppConfig := TAppConfig.Create;
  ConfigFilePath := ExtractFilePath(ParamStr(0)) + CONFIG_FILE_NAME;
  if FileExists(ConfigFilePath) then
  try
    AppConfig.LoadFromFile(ConfigFilePath, afIni);
  except

  end;
end;

{ TAppConfig }

constructor TAppConfig.Create;
begin
  inherited;
  fConnParam := TDzMSSQLADOCP.Create;
  fSettings := TServerSetting.Create;
  CityLocatePoint := 20;
  CoordLocatePoint := 20;
  SmsPoint := 10;
  Port := 7890;
  DBConnectionPoolSize := 20;
end;

destructor TAppConfig.Destroy;
begin
  fConnParam.Free;
  fSettings.Free;
  inherited;
end;

procedure TAppConfig.SetConnParam(const Value: TDzDBConnectionParam);
begin
  fConnParam.Assign(Value);
end;

initialization
  LoadConfig;

finalization
  AppConfig.Free;
  
end.
